package com.xiaoma.myaudience.biz.activity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.map.ItemizedOverlay;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Overlay;
import com.baidu.mapapi.map.OverlayItem;
import com.baidu.platform.comapi.basestruct.GeoPoint;
import com.xiaoma.myaudience.R;
import com.xiaoma.myaudience.biz.model.ActivityDetailInfoModel;
import com.xiaoma.myaudience.util.activity.BaseActivity;

/**
 * 显示地图位置点
 * 
 * @author jpren
 * 
 */
public class LocationMapActivity extends BaseActivity {
	private String key = "798d40172a066da01c7563a3236f4b53";
	BMapManager mBMapManager;
	MapView mMapView = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mBMapManager = new BMapManager(getApplicationContext());
		mBMapManager.init(key, null);
		setContentView(R.layout.location_map_layout);
		setNetEaseTitle(R.string.my_location);
		setNetEaseTitleGravity(Gravity.CENTER);
		setNetEaseTitleBarVisibility(View.VISIBLE);
		setNetEaseTitleIcon(R.drawable.home_title_icon);
		float x = 0, y = 0;
		Bundle bundle = getIntent().getExtras();
		if (bundle != null) {
			x = (float) bundle.getDouble(ActivityDetailInfoModel.PARAM_LOCATION_X);
			y = (float) bundle.getDouble(ActivityDetailInfoModel.PARAM_LOCATION_Y);

//			x = TextUtils.isEmpty(locationX) ? 39.915f : Float
//					.valueOf(locationX);
//			y = TextUtils.isEmpty(locationY) ? 116.404f : Float
//					.valueOf(locationY);
		}

		mMapView = (MapView) findViewById(R.id.bmapView);
		mMapView.getController().setZoom(17.4f);
		mMapView.getController().enableClick(true);
		GeoPoint point = new GeoPoint((int) (y * 1E6), (int) (x * 1E6));
		mMapView.getController().setCenter(point);
		
		OverlayItem item = new OverlayItem(point, "我的位置", null);
		item.setMarker(getResources().getDrawable(R.drawable.icon_gcoding));
		MyOverlay overlay = new MyOverlay(getResources().getDrawable(R.drawable.icon_gcoding), mMapView);
		overlay.addItem(item);
		mMapView.getOverlays().add(overlay);
		mMapView.refresh();
	}
	
	public class MyOverlay extends ItemizedOverlay {

		public MyOverlay(Drawable arg0, MapView arg1) {
			super(arg0, arg1);
		}
	}
}
